<?php
class Hotel extends Controller {


    public function __construct() {
        $this->load->helper('html');
    }
    public function index() {
      

    }

    public function list_hotels()
    {

      //  print_r($this->uri);
        $cityid=0;
        $is_destination=false;
        $id_alias="acc_id";
        $breadcrumb_alias="Accommodation";
        if ($this->uri->segment(4)=="dest_id"){
            $is_destination=true;
            $id_alias="dest_id";
            $breadcrumb_alias="Destination";
        }
        $id=$this->uri->segment(5);
        $sortorderarr=explode("-", $this->uri->segment(6));
        $sortorder=$sortorderarr[0];
        $cityid=$sortorderarr[1];
        $this->load->model('hotel_model');
        $this->load->model('commonmodel');
        $this->load->library("pagination");
        $config = array();
        $config["base_url"] = base_url() ."/hotel/list_hotels/".$this->uri->segment(3)."/".$id_alias."/".$id."/".$sortorder;
        if (!$is_destination){
            $config["total_rows"] = $this->hotel_model->get_hotel_list_count($id);
        }else{
            $config["total_rows"] = $this->hotel_model->get_hotel_list_dest_count($id);
        }
        $config["per_page"] = 5;
        $config["uri_segment"] = 7;
        $config['prev_tag_open'] = '<li id="pagecontroller_prev">';
        $config['prev_tag_close'] = '</li>';
        $config['next_tag_open'] = '<li id="pagecontroller_prev">';
        $config['next_tag_close'] = '</li>';
        $config['cur_tag_open'] = '<li><b>';
        $config['cur_tag_close'] = '</li></b>';
        $config['num_tag_open'] = '<li>';
        $config['num_tag_close'] = '</li>';
        $config['first_tag_open'] = '<li>';
        $config['first_tag_close'] = '</li>';
        $config['last_tag_open'] = '<li>';
        $config['lastm_tag_close'] = '</li>';

        $this->pagination->initialize($config);
        $page = ($this->uri->segment(7)) ? $this->uri->segment(7) : 0;
        $data["pagination"] = $this->pagination->create_links();
        if (!$is_destination){
            $data["hoteldetailarray"]= $this->hotel_model->get_hotel_list($id,$config["per_page"], $page,$sortorder,$cityid);
        }else{
            $data["hoteldetailarray"]= $this->hotel_model->get_hotel_list_dest($id,$config["per_page"], $page,$sortorder,$cityid);
        }        
       // print_r( $data["hoteldetailarray"]);exit;
        foreach($data["hoteldetailarray"] as $arr)
        {
            $facilityarr[$arr["hotelid"]]=$this->hotel_model->get_hotel_facilities($arr["hotelid"]);
        }
        $data["hotelfacilityarray"]= $facilityarr;
        $this->template->set('title', '');
        $this->load->library('breadcrumb');
        $this->breadcrumb->Breadcrumb();
        $this->breadcrumb->addCrumb($breadcrumb_alias);
        $this->breadcrumb->addCrumb($this->uri->segment(3));
        $data['breadcrumb'] = $this->breadcrumb->makeBread();    
        $data["acc_arr"] = $this->hotel_model->get_accomodations();
        $data["id"]=$id;
        $data["sortorder"]=$sortorder;
        $data["urisegment3"]=$this->uri->segment(3);
        $data['featured_acc_arr']=$this->hotel_model->get_featured_accomodation();
        $data["destination_arr"] = $this->hotel_model->get_destinations();
        $data["cityid"] =$cityid;
      //  print_r($data["destination_arr"]);
        $data["cityarray"] = $this->commonmodel->get_city_by_country(196);
      //  print_r($data["cityarray"]);
        $data['featured_dest_arr']=$this->hotel_model->get_featured_destination();
        $data['offers']=$this->hotel_model->get_offers();  
        $data["isdestination"]=$is_destination;
        $this->template->load('template', 'hotel_list', $data);
    }

    public function hotel_details()
    {
        $hotel_id=$this->uri->segment(4);
        $this->load->model('hotel_model');
        $hoteldetailarray= $this->hotel_model->get_hotel_details_by_hotel_id($hotel_id);        
        if ($this->uri->segment(5)=="offer"){            
            $offerdetailarray=$this->hotel_model->get_offer_list(1, 1, $this->uri->segment(4));              
            //print_r($offerdetailarray);
            $data["offerdetailarray"]=$offerdetailarray[0];
        }
        $data["hotelid"]=$hoteldetailarray["hotelid"];
        $data["hotelname"]=$hoteldetailarray["hotelname"];
        $data["hoteldesc"]=$hoteldetailarray["hoteldesc"];
        $data["ratingcount"]=$hoteldetailarray["ratingcount"];
		$data["price"]=$hoteldetailarray["price"];
        $data["mapurl"]=$hoteldetailarray["mapurl"];
        $data["hotelfacilityarray"]= $this->hotel_model->get_hotel_facilities($hotel_id);
        $data["hotelimagearray"]= $this->hotel_model->get_hotel_images($hotel_id);
        $hotelcontents=$this->hotel_model->get_hotel_content($hotel_id);
        $mealplans=$this->hotel_model->get_meal_plans_by_hotel($hotel_id);
          //print_r($hoteldetailarray);
        $meta = array(
        array('name' => 'description', 'content' => $hoteldetailarray["metadescription"]),
        array('name' => 'keywords', 'content' => $hoteldetailarray["metakeywords"]),
 
        );
        $data["location"]  =$hotelcontents["location"];
        $data["about"]  =$hotelcontents["about"];
        $data["accomodation"]  =$hotelcontents["accomodation"];
        $data["facilities"]  =$hotelcontents["facilities"];
        $data["excursion"]  =$hotelcontents["excursion"];
        $data["mealplans"]=$mealplans;
        $data["acc_arr"] = $this->hotel_model->get_accomodations();
        $data['offers']=$this->hotel_model->get_offers();  
        // print_r($data);exit;
        $this->template->set('title', $hoteldetailarray["htmltitletag"]);
         $this->template->set('metatags', meta($meta));
        $this->template->load('template', 'hotel_detail', $data);
    }

    public function list_offers()
    {       
        $this->load->model('hotel_model');
        $this->load->library("pagination");
        $config = array();
        $offer_type_id = ($this->uri->segment(3)) ? $this->uri->segment(3) : 'all';
        $page = ($this->uri->segment(4)) ? $this->uri->segment(4) : 0;
        $config["base_url"] = base_url() ."/hotel/list_offers/".$offer_type_id;    //.$this->uri->segment(3)."/".$id_alias."/".$id
        
        $config["total_rows"] = $this->hotel_model->get_offer_list_count($offer_type_id);
        
        $config["per_page"] = 5;
        $config["uri_segment"] = 5;
        $config['prev_tag_open'] = '<li id="pagecontroller_prev">';
        $config['prev_tag_close'] = '</li>';
        $config['next_tag_open'] = '<li id="pagecontroller_prev">';
        $config['next_tag_close'] = '</li>';
        $config['cur_tag_open'] = '<li><b>';
        $config['cur_tag_close'] = '</li></b>';
        $config['num_tag_open'] = '<li>';
        $config['num_tag_close'] = '</li>';
        $config['first_tag_open'] = '<li>';
        $config['first_tag_close'] = '</li>';
        $config['last_tag_open'] = '<li>';
        $config['lastm_tag_close'] = '</li>';

        $this->pagination->initialize($config);
        $data["pagination"] = $this->pagination->create_links();        
        $data["offerdetailarray"]= $this->hotel_model->get_offer_list($config["per_page"], $page, 0, $offer_type_id);
                
       // print_r( $data["hoteldetailarray"]);exit;
        $offer_type_arr=array(array("offer_type_id"=>"BH", "offer_type_name"=>"Beach Holidays"), array("offer_type_id"=>"CH", "offer_type_name"=>"Culture & Heritage Tours"), array("offer_type_id"=>"WN", "offer_type_name"=>"Wildlife & Nature Tours"), array("offer_type_id"=>"RH", "offer_type_name"=>"Romantic Holidays"));
        $this->template->set('title', '');
        $this->load->library('breadcrumb');
        $this->breadcrumb->Breadcrumb();
        $this->breadcrumb->addCrumb("Offers");
        if (strtoupper($offer_type_id)!='ALL'){
            foreach ($offer_type_arr as $val) {
                if (strtoupper($offer_type_id)==$val['offer_type_id']){
                    $this->breadcrumb->addCrumb($val['offer_type_name']);
                    break;
                }
            }
            
        }
        //$this->breadcrumb->addCrumb("Offer List");
        $data['breadcrumb'] = $this->breadcrumb->makeBread();    
        $data["acc_arr"] = $this->hotel_model->get_accomodations();
        $data['featured_acc_arr']=$this->hotel_model->get_featured_accomodation();
        $data["destination_arr"] = $this->hotel_model->get_destinations();
        $data['featured_dest_arr']=$this->hotel_model->get_featured_destination();
        $data['offers']=$this->hotel_model->get_offers();
        $this->template->load('template', 'offer_list', $data);
    }

    

}
?>
